home *** CD-ROM | disk | FTP | other *** search
- unit Grid32U;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Grids, DBGrids, Db, DBTables;
-
- type
- TForm1 = class(TForm)
- Table1: TTable;
- DataSource1: TDataSource;
- DBGrid1: TDBGrid;
- procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
- DataCol: Integer; Column: TColumn; State: TGridDrawState);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
- DataCol: Integer; Column: TColumn; State: TGridDrawState);
- var
- DataSet: TDataSet;
- begin
- with (Sender as TDBGrid) do
- begin
- DataSet := Column.Field.DataSet;
- //Our criteria means green cells, but if the cell is selected,
- //stick with the default blue background but use green font.
- if DataSet.FieldByName('TaxRate').AsFloat > 0 then
- begin
- //Selection might be due to multi-selection,
- //which needs separate checking.
- if (dgMultiSelect in Options) and
- (SelectedRows.IndexOf(DataSet.Bookmark) <> -1) then
- Include(State, gdSelected);
- if (gdSelected in State) then
- Canvas.Font.Color := clGreen
- else
- begin
- Canvas.Brush.Color := clGreen;
- Canvas.Font.Color := clWhite;
- end
- end;
- DefaultDrawColumnCell(Rect, DataCol, Column, State)
- end
- end;
-
- end.
-